<template>
  <el-table :data="list">
    <el-table-column label="员工" prop="name" />
    <el-table-column label="优先程度" prop="priority">
      <template v-slot="{row}">{{ priority[row.priority] }}</template>
    </el-table-column>
    <el-table-column label="专业" prop="profession">
      <template v-slot="{row}">{{ profession[row.profession] }}</template>
    </el-table-column>
    <div slot="append">
      <el-row :gutter="10">
        <el-form :model="data" inline class="hf_form">
          <el-col :span="8">
            <v-select v-model="data.admin_id" action="admin" />
          </el-col>
          <el-col :span="8">
            <el-form-item label>
              <el-select v-model="data.priority" size="mini">
                <el-option v-for="(item, index) in priority" :key="index" :label="item" :value="index" />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6">
            <el-form-item label>
              <el-select v-model="data.profession" size="mini">
                <el-option
                  v-for="(item, index) in profession"
                  :key="index"
                  :label="item"
                  :value="index"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="2">
            <el-form-item label>
              <el-button icon="el-icon-upload2" size="mini" @click="append" />
            </el-form-item>
          </el-col>
        </el-form>
      </el-row>
    </div>
  </el-table>
</template>
<style>
.hf_form{padding-top:10px;}
</style>
<script>
import API from '@/api/asset/location'
import { priority, profession } from '@/utils/options'
import vSelect from '@/components/select'
export default {
  name: 'Leader',
  components: { vSelect },
  props: {
    locationId: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      list: [],
      data: {},
      priority,
      profession,
      admin: [],
      adminLoading: false
    }
  },
  watch: {
    locationId() {
      this.index()
    }
  },
  created() {
    this.index()
    this.adminSelect()
  },
  methods: {
    index() {
      API.leader(this.locationId).then(response => {
        this.list = response.data.list
      })
    },
    append() {
      this.data.location_id = this.locationId
      API.append(this.data).then(() => {
        this.list.push(this.data)
      })
    },
    adminSelect() {
      API.admin().then(response => {
        this.admin = response.data.list
      })
    }
  }
}
</script>
